package org.nerve.fs.common;

/**
 * org.nerve.fs.common
 * Created by zengxm on 2015/10/8 0008.
 */
public class HexUtils {
	/**
	 * Converts the given byte buffer to a hexadecimal string using {@link java.lang.Integer#toHexString(int)}.
	 *
	 * @param bytes the bytes to convert to hex
	 * @return a String containing the hex representation of the given bytes.
	 */
	public final static String toHex(final byte[] bytes) {
		StringBuilder sb = new StringBuilder();

		for (final byte b : bytes) {
			String s = Integer.toHexString(0xff & b);

			if (s.length() < 2) {
				sb.append("0");
			}
			sb.append(s);
		}
		return sb.toString();
	}
}
